package com.jacobson.core.widget.logger

import android.util.Log

/**
 * ================================================
 * 日志输出
 * @author Wucz on 2018/7/17 11:07
 * ================================================
 */
class DefaultLoggerPrinter : Printer {
    override fun doPrint(tag: String, @LogType type: Int, level: Int, msg: String, vararg params: Any): Int {
        return println(level, tag, msg)
    }

    override fun doPrint(tag: String, @LogType type: Int, level: Int, msg: String, tr: Throwable, vararg params: Any): Int {
        return println(level, tag, msg, tr)
    }

    private fun println(level: Int, tag: String, msg: String): Int {
        return when (level) {
            Logger.Level.VERBOSE -> Log.v(tag, msg)
            Logger.Level.INFO -> Log.i(tag, msg)
            Logger.Level.WARN -> Log.w(tag, msg)
            Logger.Level.ERROR -> Log.e(tag, msg)
            Logger.Level.ASSERT -> Log.wtf(tag, msg)
            Logger.Level.DEBUG -> Log.d(tag, msg)
            else -> Log.d(tag, msg)
        }
    }

    private fun println(level: Int, tag: String, msg: String, tr: Throwable): Int {
        return when (level) {
            Logger.Level.VERBOSE -> Log.v(tag, msg, tr)
            Logger.Level.INFO -> Log.i(tag, msg, tr)
            Logger.Level.WARN -> Log.w(tag, msg, tr)
            Logger.Level.ERROR -> Log.e(tag, msg, tr)
            Logger.Level.ASSERT -> Log.wtf(tag, msg, tr)
            Logger.Level.DEBUG -> Log.d(tag, msg, tr)
            else -> Log.d(tag, msg, tr)
        }
    }
}